import { Inject, Controller, Get, Query, Post, Body, App, All } from "@midwayjs/core";
import { Context } from '@midwayjs/koa';
import { HttpService } from '@midwayjs/axios'
// const  {exec}  =require( 'child_process')
import { Application } from "../interface.js";
import { app_fun_dto } from "../models/app_fun.dto.js";
import { failres, okres } from "../config/resUtil.js";
import { UserService } from "../service/user.service.js";
const routermap = {
    "个人":"http://127.0.0.1:7001" + "/api/user/apis",
    "生产代码":"http://127.0.0.1:7001" + "/api/gerenrate/apis",
    
}
@Controller('/apis')
export class APIController {
    @Inject()
    ctx: Context;
    @App('koa')
    app: Application;

    @Inject()
    userService: UserService;

    @Inject()
    httpService: HttpService;


    @All('')
    async getUser(@Body() body) {
        var _name = body?._name;
        if (!_name) {
            return failres('_name post body必填')
        }

        var 模块 = body?.['模块'];
        if (!模块) {
            return failres('模块 post body必填')
        }

        var url = routermap[模块];


        var result = await this.httpService.post<any, any>(url, body).then(res=>res.data)
        console.log('result :', result);
    
return {
code:result?.code,
success:result?.success,
data:result?.data,
message:result?.message
};

       
    }
}
